package com.functionx;

import com.functionx.consumer.SampleService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Hello world!
 */
public class App {

    private static final AtomicInteger index = new AtomicInteger();
    private static final ExecutorService threadPool =
            new ThreadPoolExecutor(5, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS,
                    new SynchronousQueue<>(),
                    (run) -> new Thread(run, "Worker-" + index.incrementAndGet()));

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:appcontext.xml");
        SampleService sampleService = (SampleService) context.getBean("sampleService");
        System.out.println(sampleService.work());
    }
}
